/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.examples;

import br.ufba.lasid.v1.jitclouds.mda.MDA;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.ICluster;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.virtualization.IHypervisor;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.virtualization.INode;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.virtualization.IVirtualMachine;
import br.ufba.lasid.v1.jitclouds.mda.providers.ClusterProvider;

/**
 *
 * @author aliriosa
 */
public class ClusterSample {
    
   public static void main(String[] args) throws Exception{
       
       MDA.startup();
       
      ICluster cluster = MDA.createCluster();
      
      MDA.debug("Starting machines from each node in cluster ... ");
      
      for(INode node : cluster){
          MDA.debug("Obtaing hypervisor of node " + node.getID());
          for(IHypervisor hypervisor : node.getHypervisors()){
              MDA.debug("Starting virtual machines of " + hypervisor.getID() + "@" + node.getID());
              for(IVirtualMachine machine : hypervisor.getMachines()){
                  machine.startup();
              }
          }
      }
      
      MDA.debug("Cluster startup complete ... ");
      
      MDA.debug("Halting machines from each node in cluster ... ");
      
      for(INode node : cluster){
          MDA.debug("Obtaing hypervisor of node " + node.getID());
          for(IHypervisor hypervisor : node.getHypervisors()){
              MDA.debug("Halting virtual machines of " + hypervisor.getID() + "@" + node.getID());
              for(IVirtualMachine machine : hypervisor.getMachines()){
                  machine.shutdown();
              }
          }
      }
      
      MDA.debug("Cluster shutdown complete ... ");
   }
    
}
